package com.sjy.ylxt.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.sjy.ylxt.entity.basic.ResultBody;
import com.sjy.ylxt.entity.dto.QueryPatientDTO;
import com.sjy.ylxt.service.YlxtPatientService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: 史俊颖
 * @CreateTime: 2024-12-12
 * @Description:
 */
/**
 * 患者管理
 */
@RestController
@RequestMapping("/patient")
public class PatientController {

    @Resource
    private YlxtPatientService ylxtPatientService;

    /**
     * 查询患者列表
     * @param pageNum
     * @param pageSize
     * @param userName
     * @param phoneNumber
     * @param email
     * @return
     */
    @PostMapping("/page-list")
    public ResultBody<?> pageList(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String userName,
            @RequestParam(required = false) String phoneNumber,
            @RequestParam(required = false) String email) {
        QueryPatientDTO dto = new QueryPatientDTO();
        dto.setPageNum(pageNum);
        dto.setPageSize(pageSize);
        dto.setUserName(userName);
        dto.setPhoneNumber(phoneNumber);
        dto.setEmail(email);
        return ylxtPatientService.queryPatient(dto);
    }

    /**
     * 删除患者
     */
    @PostMapping("/delete")
    public ResultBody<?> delete(@RequestParam String id){
        return ResultBody.success(ylxtPatientService.deleteByPrimaryKey(Integer.valueOf(id)));
    }

    /**
     * 查看详情
     */
    @PostMapping("/detail")
    public ResultBody<?> detail(@RequestParam String id){
        return ResultBody.success(ylxtPatientService.selectByPrimaryKey(Integer.valueOf(id)));
    }
}
